export const HomePage = {
	data() {
		return {
			currentPage: '',
			var_options: {} //缓存传入数据
		}
	},
	watch: {
		currentPage() {
			this.refInit();
			this.refEvent('$onShow');
		}
	},
	onLoad(options) {
		this.var_options = options;
	},
	onReady(e) {
		this.refInit(this.var_options);
	},
	onShow(e) {
		this.$nextTick(() => {
			this.refEvent('$onShow', e);
		})
	},
	onHide(e) {
		this.refEvent('$onHide', e);
	},
	onUnload(e) {
		this.refEvent('$onUnload', e);
	},
	onPullDownRefresh(e) {
		this.refEvent('$onPullDownRefresh', e);
	},
	onReachBottom(e) {
		this.refEvent('$onReachBottom', e);
	},
	onShareAppMessage(e) {
		this.refEvent('$onShareAppMessage', e);
	},
	onPageScroll(e) {
		this.refEvent('$onPageScroll', e);
	},
	onResize(e) {
		this.refEvent('$onResize', e);
	},
	onTabItemTap(e) {
		this.refEvent('$onTabItemTap', e);
	},
	onPageScroll(e) {
		this.refEvent('$onPageScroll', e);
	},
	methods: {
		refInit(e) {
			let page = this.$refs[this.currentPage];
			if (!page.pageInitState) {
				page.pageInitState = true;
				this.refEvent('$onLoad', e);
				this.refEvent('$onReady');
			}
		},
		refEvent(eventName, e = {}) {
			let page = this.$refs[this.currentPage];
			if (page) {
				if (page[eventName]) {
					page[eventName](e);
				}
				// page[eventName]?.call(e);
			} else {
				console.warn('找不到', this.currentPage, '页面', '没法执行', eventName);
			}
			// this.$refs[this.currentPage][eventName]?.call(e);
		},
	}
}
